package com.auto.controller;

import com.auto.domain.User;
import com.auto.service.UserService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@RestController
public class UserController {
    @Autowired
    private UserService userService;

    @GetMapping("/findAll")
    public ModelAndView findAll() {
        PageHelper.startPage(1, 2);
        Page<User> userPage = userService.findAll();
        List<User> userList = userPage.getResult();
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("index");
        modelAndView.addObject("userList", userList);
        return modelAndView;
    }

    @GetMapping("/page")
    public List<User> findUserPage(){
        PageHelper.startPage(1, 2);
        Page<User> userPage = userService.findAll();
        return userPage.getResult();
    }
}

